package test.comparator;



import java.util.Comparator;

import com.yaoxiaowen.utils.Utils_Time;

/**
 * YaoWen(43194) create at tongcheng work pc,
 * time:  2016/12/20 14:00  qq:2669932513
 *
 * Notice:对代金券进行排序的方法，
 * 排序方式按照 李俊音 V1.1PRD.doc文档
 *
 * 按可用与否>金额大小>到期日期排序，
 */
public class CouponsComparator implements Comparator<CouponsInfoBean>{

    public int compare(CouponsInfoBean first, CouponsInfoBean second) {
        int stateDiff = Integer.parseInt(first.getStatus()) - Integer.parseInt(second.getStatus());
        if (stateDiff != 0){
            return stateDiff;
        }

        float parValueDiff = Float.parseFloat(first.getParValue()) - Float.parseFloat(second.getParValue());
        //float类型 不能与0 直接比较，所以我们就这样写
        if (!first.getParValue().equals(second.getParValue())){
            if (parValueDiff > 0){
                return -1;
            }else  if (parValueDiff < 0){
                return 1;
            }
        }

        long timeDiff = Utils_Time.formatTime2TimeStamp(second.getEndTime()) - Utils_Time.formatTime2TimeStamp(first.getEndTime());
        return (int) timeDiff;
    }

}
